//
//  SDSDUnderlineButton.m
//  SuperDoctor
//
//  Created by 李忠 on 7/6/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDUnderlineButton.h"
#import "UIView+SDExtension.h"

@interface SDUnderlineButton ()

@property (nonatomic, strong) UIColor *underLindeColor;

@end
@implementation SDUnderlineButton


- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    
    [super setTitle:title forState:state];
    self.underLindeColor = self.currentTitleColor;
    [self setNeedsDisplay];
     
}

- (void)drawRect:(CGRect)rect{
    
    
    
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    CGFloat width = self.titleLabel.sdWidth;
    CGFloat startX = self.titleLabel.sdX;
    CGFloat startY = CGRectGetMaxY(self.titleLabel.frame)+2;
    CGFloat endX = startX + width;
    CGFloat endY = startY;
    
    [bezierPath moveToPoint:CGPointMake(startX, startY)];
    [bezierPath addLineToPoint:CGPointMake(endX, endY)];
    [self.underLindeColor setStroke];
    [bezierPath setLineWidth:1];
    [bezierPath stroke];
    
}

@end
